﻿using MiniExcelLibs;
using MiniExcelLibs.Csv;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Auxiliary
{
    public class AppExcel
    {
        private const string newline = "\n";
        private CsvConfiguration csvConfig;

        public AppExcel()
        {
            csvConfig = new MiniExcelLibs.Csv.CsvConfiguration()
            {
                Seperator = ';',
                NewLine = newline

            };
        }
        public long Export(DataTable dataTable, string fileFullPath)
        {
            var n = dataTable.Rows.Count;
            MiniExcel.SaveAs(fileFullPath, dataTable);
            return n;
        }

        public long Export(object values, string fileFullPath)
        {
            MiniExcel.SaveAs(fileFullPath, values);
            return 1;
        }


        public long Export(DataTable dataTable, string fileFullPath, string templatePath)
        {
            var n = dataTable.Rows.Count;
            MiniExcel.SaveAsByTemplate(fileFullPath, templatePath, dataTable);
            return n;
        }

        public bool Export<T>(string fileFullPath, string templatePath, T data)
        {          
            MiniExcel.SaveAsByTemplate(fileFullPath, templatePath, data);
            return true;
        }
    }
}
